package com.my.test.thread.executors;

import java.util.Date;
import java.util.concurrent.*;

public class MyExecutors extends ThreadPoolExecutor {

    public MyExecutors(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) {
        super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
    }

    @Override
    public void shutdown() {
        System.out.println("执行完毕");
        super.shutdown();
    }

    @Override
    protected void beforeExecute(Thread t, Runnable r) {
        super.beforeExecute(t, r);
        System.out.println(Thread.currentThread().getName()+" "+":beforeExecute:"+new Date());
    }

    @Override
    protected void afterExecute(Runnable r, Throwable t) {
        super.afterExecute(r, t);
        System.out.println("线程的空闲时间" + this.getKeepAliveTime(TimeUnit.MILLISECONDS));
        System.out.println("任务总数:" + this.getTaskCount());
        System.out.println("当前排队线程数:"+this.getQueue().size());
        System.out.println("当前活动线程数:"+this.getActiveCount());
        System.out.println(Thread.currentThread().getName()+"  "+"afterExecute:"+new Date());
    }


    public static ExecutorService newMyExecutors(){
       return new MyExecutors(10,100,60l,TimeUnit.SECONDS,new SynchronousQueue<Runnable>());
    }



}
